# Maintainer: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>

_realname=cvode
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.5.0
pkgrel=1
pkgdesc="ordinary differential equation system solver (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://computing.llnl.gov/projects/sundials/cvode"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/LLNL/sundials/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-install-location.patch)
sha256sums=('30fd7194296a1c4530d0573348c2db07e1852c5e95d275e43c49d18d39e91279'
            'd2860ecbc67e43abf5cc34ef39b5f6fdb64ee8495be4067bb7a99adcdec09912')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-install-location.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  cmake --build .
}

package() {
  cd build-${MINGW_CHOST}
  DESTDIR=${pkgdir} cmake --install .

  # license
  rm ${pkgdir}${MINGW_PREFIX}/include/sundials/LICENSE
  install -D -m644 ${srcdir}/${_realname}-${pkgver}/LICENSE \
  ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
